package org.netEase.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.netEase.dao.zhanghuDao;
import org.netEase.entity.comment;
import org.netEase.entity.yonghu;
import org.netEase.entity.zhanghu;
import org.netEase.entity.zhuti;
import org.netEase.util.BaseDao;

public class zhanghuimpl extends BaseDao implements zhanghuDao {

	@Override
	public  zhanghu getID(String name, String password) {
		 
		String sql="select * from  zhanghu where name=? and password=? and lei=1";
		ResultSet rs = super.executeQuery(sql,name,password);
		zhanghu zhang=null; 
		try {
			while(rs.next()) {
				zhang = new  zhanghu();
				zhang.setLei(rs.getInt("Lei"));
				zhang.setHid(rs.getInt("Hid"));
				zhang.setStateid(rs.getString("stateid"));
				zhang.setNamesp(rs.getString("Namesp"));
				zhang.setName(rs.getString("name"));
				zhang.setPassword(rs.getString("password"));
				zhang.setToimg(rs.getString("toimg"));
				zhang.setSex(rs.getString("sex"));
				zhang.setPione(rs.getString("pione"));
				zhang.setDataday(rs.getDate("dataday"));
				zhang.setSchoolname(rs.getString("schoolname"));		
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally {
			try {
				closeAll(rs.getStatement().getConnection(), rs.getStatement(), rs);
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return zhang;
	}

	@Override
	public List<zhanghu> getAid() {
		
		List<zhanghu> list = new ArrayList<>();
		String sql="select * from  zhanghu";
		ResultSet rs = super.executeQuery(sql);
		
		try {
			while(rs.next()) {
				zhanghu	zhang = new  zhanghu();
				zhang.setLei(rs.getInt("Lei"));
				zhang.setHid(rs.getInt("Hid"));
				zhang.setStateid(rs.getString("stateid"));
				zhang.setNamesp(rs.getString("Namesp"));
				zhang.setName(rs.getString("name"));
				zhang.setPassword(rs.getString("password"));
				zhang.setToimg(rs.getString("toimg"));
				zhang.setSex(rs.getString("sex"));
				zhang.setPione(rs.getString("pione"));
				zhang.setDataday(rs.getDate("dataday"));
				zhang.setSchoolname(rs.getString("schoolname"));
				list.add(zhang);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally {
			try {
				closeAll(rs.getStatement().getConnection(), rs.getStatement(), rs);
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return list;
	}

	@Override
	public int add(zhanghu zh) {
		  String sql = "insert into `zhanghu` ( lei,namesp,name,password,toimg,sex,pione,dataday,schoolname) values (?,?,?,?,?,?,?,?,?)";	
		  return super.executeUpdate(sql,zh.getLei(),zh.getNamesp(),zh.getName(),zh.getPassword(),zh.getToimg(),zh.getSex(),zh.getPione(),zh.getDataday(),zh.getSchoolname());
			
	}
	}